package cn.edu.lingnan.Listener;

import cn.edu.lingnan.entity.excelPojo.StudentContest;
import cn.edu.lingnan.service.ExcelService;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Component
@Scope("prototype")
public class StudentsListener extends AnalysisEventListener<StudentContest> {

    @Autowired
    ExcelService excelService;

    private static int index = 1;

    @Override
    @Transactional
    public void invoke(StudentContest studentContest, AnalysisContext analysisContext) {
        //把id移除
        studentContest.setId((long) (excelService.count()+1));
            excelService.save(studentContest);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
//        saveData();
    }

//    private void saveData() {
//        if (!batchList.isEmpty()) {
//            excelService.saveBatch(batchList);
//        }
//    }
}
